package com.jservice.api.service.smk;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jservice.api.dto.Request;
import com.jservice.api.dto.Response;
import com.jservice.api.dto.ResponseHeader;
import com.jservice.api.service.BaseService;
import com.jservice.api.service.IService;
import com.jservice.model.SmkNews;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Smk0012 - 首页 资讯列表(分页)
 *
 * @Author cwledit
 * @DATE 2017/6/17.
 */
@Service("smk0012")
public class Smk0012 extends BaseService implements IService{
    @Override
    public Response excute(Request request, Response response, ResponseHeader header, String method) throws Exception {
        Map paramMap =  request.getData();
        Integer display_no = paramsIntegerFilter(paramMap.get("display_no"));
        Integer current_page_no = paramsIntegerFilter(paramMap.get("current_page_no"));
        if (display_no == null){
            display_no = 10;
        }
        if (current_page_no == null){
            current_page_no = 1;
        }
        String sqlSelect = "select sn.icon_url, sn.title,sn.sub_title, sn.id, sn.create_date ";
        String sql = "from "+ SmkNews.TABLE_NAME+" sn where sn.status = 'ONLINE' order by orders desc," +
        " create_date desc";
        Page page = Db.paginate(current_page_no,display_no,sqlSelect,sql);
        return renderSUC(page,response,header);
    }
}
